package com.base.cn.platform.os.controller.agent.settlement;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.agent.settlement.AgentSettlementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 累计结算周期列表接口
 *
 * @author s.li
 * @create 2018-09-26-19:08
 */
@RestController
@RequestMapping("/api/agent/settlement")
public class ApiAgentSettlementController extends ApiBaseController {

    @Autowired
    private AgentSettlementService agentSettlementService;

    /**
     * 累计结算周期列表
     * @return
     */
    @RequestMapping("/querySettlementList")
    public Map<String,Object> querySettlementList(@RequestParam("agentId") BigDecimal agentId,
                                                  @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        Map<String,Object> params = new HashMap<>();
        params.put("agentUserId",agentId);
        Map<String, Object> dataMap = agentSettlementService.querySettlementListPage(currentPage, params, false);
        return ResultUtil.SUCCESS(dataMap);
    }

    /**
     * 确认结算接口
     * @param userId
     * @param settlementFrom 结算来源，1H5，2App，3小程序
     * @return Map<String,Object>
     */
    @RequestMapping("/confirmSettlement")
    public Map<String,Object> confirmSettlement(@RequestParam("userId") BigDecimal userId,
                                                   @RequestParam("settlementFrom") int settlementFrom){
        Map<String, Object> params = new HashMap<>();
        params.put("settlementFrom",settlementFrom);
        return agentSettlementService.confirmSettlement(params, userId);
    }

    /**
     *  查看结算周期明细
     * @param settlementId 结算周期ID
     * @param userId 用户ID
     * @return Map<String,Object>
     */
    @RequestMapping("/findSettlementById")
    public Map<String,Object> findSettlementById(@RequestParam("settlementId") BigDecimal settlementId,
                                                 @RequestParam("userId") BigDecimal userId ){
        Map<String, Object> settlement = agentSettlementService.findSettlementById(settlementId, false);
        return ResultUtil.SUCCESS(settlement);
    }

}
